<template>
  <div class="wa-card wa-file-category" ref="contentRef">

  </div>
</template>

<script setup>
import * as echarts from 'echarts';
import {onMounted, ref, defineProps} from "vue";

const props = defineProps({
  title: {
    type: String,
    required: true
  },
  data: {
    type: Array,
    required: true
  }
})

const contentRef = ref()
onMounted(() => {
  const myChart = echarts.init(contentRef.value);
  myChart.setOption({
    title: {
      text: props.title,
      left: 'center'
    },
    tooltip: {
      trigger: 'item'
    },
    legend: {
      top: '5%',
      left: 'center'
    },
  })
  const timer = setInterval(() => {
    if (props.data) {
      clearInterval(timer)
      myChart.setOption({
        series: [
          {
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: 'center'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: 40,
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: false
            },
            data: props.data
          }
        ]
      })
    }
  }, 500)
})
</script>

<style lang="less" scoped>
.wa-file-category {
  margin-right: 20px;
  height: 400px;
}
</style>